﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary.Entities;
using System.Globalization;
using CMISLibrary;
using BCNPCObject.DB;
namespace BCNPCObject
{
    public class cls_CN_HDON_PHTHU_Controller
    {
        #region   Atributes

        private DataSet CMIS_Header = new CMISOutputParameter();
        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private cls_CN_HDON_PHTHU_Info info;
        private CN_HDON_PHTHU infoNew;
        private List<CN_HDON_PHTHU> infolst;
        #endregion

        #region   Constructor

        public cls_CN_HDON_PHTHU_Controller()
        {
            info = new cls_CN_HDON_PHTHU_Info();
            infoNew = new CN_HDON_PHTHU();
            infolst = new List<CN_HDON_PHTHU>();
        }
        public cls_CN_HDON_PHTHU_Controller(cls_CN_HDON_PHTHU_Info Info)
        {
            this.info = Info;
        }
        public cls_CN_HDON_PHTHU_Controller(CN_HDON_PHTHU InfoNew, int i)
        {
            this.infoNew = InfoNew;
        }
        public cls_CN_HDON_PHTHU_Controller(List<CN_HDON_PHTHU> InfoLst, int i, int j)
        {
            this.infolst = InfoLst;
        }
        #endregion

        #region   Properties

        public cls_CN_HDON_PHTHU_Info pInfor
        {
            get { return info; }
            set { info = value; }
        }

        public List<CN_HDON_PHTHU> pListInfo
        {
            set
            {
                this.infolst = value;
            }
        }
       
        #endregion

        #region   Methods

        
        public bool insert_CN_HDON_PHTHU()
        {    
            try
            {
                CN_HDON_PHTHU objCN_HDON_PHTHU = new CN_HDON_PHTHU()
                {
                    MA_CNANG = info.MA_CNANG,
                    ID_HDON = info.ID_HDON,
                    LOAI_HDON = info.LOAI_HDON,
                    MA_DVIQLY = info.MA_DVIQLY,
                    MA_PTTT = info.MA_PTTT,
                    MA_TNGAN = info.MA_TNGAN,
                    NGAY_NOP = info.NGAY_NOP,
                    NGAY_SUA = info.NGAY_SUA,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_SUA = info.NGUOI_SUA,
                    NGUOI_TAO = info.NGUOI_TAO,
                    SO_PHTHU = info.SO_PHTHU,
                    THUE_NOP = info.THUE_NOP,
                    TIEN_NOP = info.TIEN_NOP,
                };
                CMIS2.DB.CN_HDON_PHTHU.InsertOnSubmit(objCN_HDON_PHTHU);
                //this.CMIS2.DB.SubmitChanges();
                //CMIS2.ResetDB();
                return true;
            }
            catch
            {
                //CMIS2.ResetDB(); 
                return false;
            }
        }
        public Int64 GetIDSequence()
        {
            try
            {
                /*var query = from p in CMIS2.DB.CN_PHIEU_THU
                            where p.MA_DVIQLY == strMadonvi
                            select p.SO_PHTHU;
                if (query.ToList().Count > 0) return Convert.ToInt32(query.Max()) + 1;
                else return 1;*/

                string stra = "";
                long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_CN_PHIEU_THU.NEXTVAL from dual", ref stra);
                return _ID;
            }
            catch
            {
                //CMIS2.ResetDB(); 
                return -1;
            }
        }      
        public bool update_CN_HDON_PHTHU()
        {
            try
            {
                CN_HDON_PHTHU objCN_HDON_PHTHU = CMIS2.DB.CN_HDON_PHTHU.Single(c => c.ID_HDON == info.ID_HDON && c.LOAI_HDON == info.LOAI_HDON && c.MA_DVIQLY == info.MA_DVIQLY);
                objCN_HDON_PHTHU.MA_CNANG = info.MA_CNANG;
                objCN_HDON_PHTHU.MA_PTTT = info.MA_PTTT;
                objCN_HDON_PHTHU.MA_TNGAN = info.MA_TNGAN;
                objCN_HDON_PHTHU.NGAY_NOP = info.NGAY_NOP;
                objCN_HDON_PHTHU.NGAY_SUA = info.NGAY_SUA;
                objCN_HDON_PHTHU.NGAY_TAO = info.NGAY_TAO;
                objCN_HDON_PHTHU.NGUOI_SUA = info.NGUOI_SUA;
                objCN_HDON_PHTHU.NGUOI_TAO = info.NGUOI_TAO;
                objCN_HDON_PHTHU.SO_PHTHU = info.SO_PHTHU;
                objCN_HDON_PHTHU.THUE_NOP = info.THUE_NOP;
                objCN_HDON_PHTHU.TIEN_NOP = info.TIEN_NOP;
                //this.CMIS2.DB.SubmitChanges();
                return true;
            }
            catch
            {
                //CMIS2.ResetDB(); 
                return false;
            }
        }
        public bool delete_CN_HDON_PHTHU_ATM( string strMadonvi, string strLoaihdon, long pID_hdon, ref long psophieuthu)
        {
            try
            {
                var query = from p in CMIS2.DB.CN_HDON_PHTHU where p.ID_HDON == pID_hdon && p.LOAI_HDON == strLoaihdon && p.MA_DVIQLY == strMadonvi select p;
                psophieuthu = query.Where(c=>c.MA_DVIQLY==strMadonvi && c.LOAI_HDON==strLoaihdon && c.ID_HDON==pID_hdon).Select(c=>c.SO_PHTHU).First();
                if (query != null && query.Count() > 0)
                {
                    CMIS2.DB.CN_HDON_PHTHU.DeleteAllOnSubmit(query.ToList());
                    //this.CMIS2.DB.SubmitChanges();
                    return true;
                }
                return true;
            }
            catch
            {
                //CMIS2.ResetDB(); 
                return false;
            }
        }
        public bool delete_CN_HDON_PHTHU_ByPK(System.Int64 pr_ID_HDON, System.String pr_LOAI_HDON, System.String pr_MA_DVIQLY)
        {
            try
            {
                var query = from p in CMIS2.DB.CN_HDON_PHTHU where p.ID_HDON == pr_ID_HDON && p.LOAI_HDON == pr_LOAI_HDON && p.MA_DVIQLY == pr_MA_DVIQLY select p;
                if (query != null && query.Count() > 0)
                {
                    CMIS2.DB.CN_HDON_PHTHU.DeleteAllOnSubmit(query.ToList());
                    //this.CMIS2.DB.SubmitChanges();
                    return true;
                }
                return true;
            }
            catch
            {
                //CMIS2.ResetDB(); 
                return false;
            }
        }

        #endregion


      
    }
}
